package com.applet.code.util;

import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

@Slf4j
public class FileUtils {

	private FileUtils() {}
	
	public static void uploadFile(byte[] file, String filePath, String fileName) { 
        File targetFile = new File(filePath);  
        if(!targetFile.exists()){    
            targetFile.mkdirs();    
        }       
        FileOutputStream out = null;
        String fileAllPath = new StringBuilder(filePath).append(File.separator).append(fileName).toString();
        log.debug("上传文件路径:{}", fileAllPath);
		try {
			out = new FileOutputStream(fileAllPath);
	        out.write(file);
	        out.flush();
		} catch (IOException e) {
			log.error("uploadFile", e);
		} finally {
			if (out != null) {
		        try {
					out.close();
				} catch (IOException e) {
					log.error("uploadFile - close", e);
				}
			}
		}
    }
}
